import { Style, Circle, Stroke, Fill, Text, Icon } from "ol/style";

/**
 * 根据水质类别获取对应的颜色
 * @param {string|number} qualityLevel - 水质类别 (I, II, III, IV, V, 劣V)
 * @returns {string} 颜色值
 */
export function getWaterQualityColor(qualityLevel) {
  const colorMap = {
    Ⅰ类: "rgb(204, 255, 255)", // 优 #ccffff
    Ⅱ类: "rgb(0, 204, 255)", // 良好 #00ccff
    Ⅲ类: "rgb(0, 255, 0)", // 轻度污染 #00ff00
    Ⅳ类: "rgb(255, 255, 0)", // 中度污染 #ffff00
    Ⅴ类: "rgb(255, 155, 0)", // 重度污染 #ff9b00
    劣Ⅴ类: "rgb(255, 0, 0)", // 严重污染 #ff0000
    无类别: "#FC8452", // 无类别水质
    0: "#FC8452", // 自定义颜色
    1: "rgb(204, 255, 255)",
    2: "rgb(0, 204, 255)",
    3: "rgb(0, 255, 0)",
    4: "rgb(255, 255, 0)",
    5: "rgb(255, 155, 0)",
    6: "rgb(255, 0, 0)",
    7: "#FC8452", // 无类别水质
  };

  return colorMap[qualityLevel] || "rgba(128, 128, 128, 0.8)"; // 默认灰色
}

// 自动监测站图片导入
import guokong1 from "@/assets/map/water/国控1.png";
import guokong2 from "@/assets/map/water/国控2.png";
import guokong3 from "@/assets/map/water/国控3.png";
import guokong4 from "@/assets/map/water/国控4.png";
import guokong5 from "@/assets/map/water/国控5.png";
import guokong6 from "@/assets/map/water/国控6.png";

import shengkong1 from "@/assets/map/water/省控1.png";
import shengkong2 from "@/assets/map/water/省控2.png";
import shengkong3 from "@/assets/map/water/省控3.png";
import shengkong4 from "@/assets/map/water/省控4.png";
import shengkong5 from "@/assets/map/water/省控5.png";
import shengkong6 from "@/assets/map/water/省控6.png";

import shikong1 from "@/assets/map/water/市控1.png";
import shikong2 from "@/assets/map/water/市控2.png";
import shikong3 from "@/assets/map/water/市控3.png";
import shikong4 from "@/assets/map/water/市控4.png";
import shikong5 from "@/assets/map/water/市控5.png";
import shikong6 from "@/assets/map/water/市控6.png";

import xiankong1 from "@/assets/map/water/县控1.png";
import xiankong2 from "@/assets/map/water/县控2.png";
import xiankong3 from "@/assets/map/water/县控3.png";
import xiankong4 from "@/assets/map/water/县控4.png";
import xiankong5 from "@/assets/map/water/县控5.png";
import xiankong6 from "@/assets/map/water/县控6.png";

// 手工监测站图片导入
import sg1 from "@/assets/map/water/一类水质.png";
import sg2 from "@/assets/map/water/二类水质.png";
import sg3 from "@/assets/map/water/三类水质.png";
import sg4 from "@/assets/map/water/四类水质.png";
import sg5 from "@/assets/map/water/五类水质.png";
import sg6 from "@/assets/map/water/劣五类水质.png";
import sg7 from "@/assets/map/water/map_water_7.png";

// 水源地水质监测站图片导入
import syd1 from "@/assets/map/water/水源站1.png";
import syd2 from "@/assets/map/water/水源站2.png";
import syd3 from "@/assets/map/water/水源站3.png";
import syd4 from "@/assets/map/water/水源站4.png";
import syd5 from "@/assets/map/water/水源站5.png";
import syd6 from "@/assets/map/water/水源站6.png";

// 其他图片导入
import qushuikouImage from "@/assets/map/water/地表水取水口.png";
import wuranyuanImage from "@/assets/map/pollution/污染源.png";

// 入河排污口图片导入
import pwk1 from "@/assets/map/paiwukou/城镇污水处理厂排污口.png";
import pwk2 from "@/assets/map/paiwukou/工业排污口.png";
import pwk3 from "@/assets/map/paiwukou/农业排口.png";
import pwk4 from "@/assets/map/paiwukou/其他排污口.png";

import yujingImage from "@/assets/map/warn/warn.png";

import StringUtils from "../utils/string_utils";

// 自动监测站
const zdWaterQualityImages = {
  国控: {
    1: guokong1,
    2: guokong2,
    3: guokong3,
    4: guokong4,
    5: guokong5,
    6: guokong6,
  },
  省控: {
    1: shengkong1,
    2: shengkong2,
    3: shengkong3,
    4: shengkong4,
    5: shengkong5,
    6: shengkong6,
  },
  市控: {
    1: shikong1,
    2: shikong2,
    3: shikong3,
    4: shikong4,
    5: shikong5,
    6: shikong6,
  },
  县控: {
    1: xiankong1,
    2: xiankong2,
    3: xiankong3,
    4: xiankong4,
    5: xiankong5,
    6: xiankong6,
  },
};

// 手工监测站
const sgWaterQualityImages = {
  1: sg1,
  2: sg2,
  3: sg3,
  4: sg4,
  5: sg5,
  6: sg6,
  7: sg7,
  0: sg7,
};

// 水源地水质监测站
const shuiyuandiStationImages = {
  1: syd1,
  2: syd2,
  3: syd3,
  4: syd4,
  5: syd5,
  6: syd6,
};

// 入河排污口
const paiwukouImages = {
  1: pwk1,
  2: pwk2,
  3: pwk3,
  4: pwk4,
};

/**
 * 创建自动监测站样式（使用图片）
 * @param {ol.Feature} feature - 要素对象
 * @returns {Style} 样式对象
 */
export function createWaterSectionStyle(feature) {
  const properties = feature.getProperties();
  const controllevel = properties.controllevel || "省控";
  const qualityLevel = properties.qualityLevel || "2";

  // 获取对应的图片
  const imageSrc =
    zdWaterQualityImages[controllevel][qualityLevel] ||
    zdWaterQualityImages["省控"]["2"]; // 默认使用二类水质图片

  return new Style({
    image: new Icon({
      src: imageSrc,
      scale: 0.75,
      anchor: [0.5, 0.5],
    }),
  });
}

/**
 * 创建手工断面样式（使用图片）
 * @param {ol.Feature} feature - 要素对象
 * @returns {Style} 样式对象
 */
export function createShougongduanStyle(feature) {
  const properties = feature.getProperties();
  let qualityLevel = StringUtils.parseInt(properties.qualityLevel);
  console.log(parseInt(properties.qualityLevel),qualityLevel)
  // 获取对应的图片
  const imageSrc =
    sgWaterQualityImages[qualityLevel] || sgWaterQualityImages["2"]; // 默认使用二类水质图片

  return new Style({
    image: new Icon({
      src: imageSrc,
      scale: 0.75,
      anchor: [0.5, 0.5],
    }),
  });
}

/**
 * 创建水源地水质监测站样式
 * @param {ol.Feature} feature - 要素对象
 * @returns {Style} 样式对象
 */
export function createshuiyuandiStationStyle(feature) {
  const properties = feature.getProperties();
  const qualityLevel = properties.qualityLevel || "2";
  // 获取对应的图片
  const imageSrc =
    shuiyuandiStationImages[qualityLevel] || shuiyuandiStationImages["2"]; // 默认使用二类水质图片

  return new Style({
    image: new Icon({
      src: imageSrc,
      scale: 0.75,
      anchor: [0.5, 0.5],
    }),
  });
}

export function createQushuikouStyle(feature) {
  // 获取对应的图片
  const imageSrc = qushuikouImage;
  return new Style({
    image: new Icon({
      src: imageSrc,
      scale: 0.75,
      anchor: [0.5, 0.5],
    }),
  });
}

export function createWuranyuanStyle(feature) {
  // 获取对应的图片
  const imageSrc = wuranyuanImage;
  return new Style({
    image: new Icon({
      src: imageSrc,
      scale: 0.75,
      anchor: [0.5, 0.5],
    }),
  });
}

export function createPaiwukouStyle(feature) {
  const properties = feature.getProperties();
  const outfallcode = properties.outfallcode || "4";
  // 获取对应的图片
  const imageSrc = paiwukouImages[outfallcode] || paiwukouImages["4"]; // 默认使用其他排污口

  return new Style({
    image: new Icon({
      src: imageSrc,
      scale: 0.75,
      anchor: [0.5, 0.5],
    }),
  });
}

export function createYujingStyle(feature) {
  // 获取对应的图片
  const imageSrc = yujingImage;
  return new Style({
    image: new Icon({
      src: imageSrc,
      scale: 0.75,
      anchor: [0.5, 0.5],
    }),
  });
}

/**
 * 根据创建点样式
 * @param {string} layerId - 图层id
 * @returns {Function} 样式函数
 */
export function createPointStyleFunction(layerId) {
  // 水质监测图层样式
  if (
    layerId === "guokongzhan" ||
    layerId === "shengkongzhan" ||
    layerId === "shikongzhan" ||
    layerId === "xiankongzhan"
  ) {
    return createWaterSectionStyle;
  }

  if (layerId === "zidongzhan") {
    return createWaterSectionStyle;
  }
  
  // 水质监测图层样式
  if (layerId === "shougongduanmian") {
    return createShougongduanStyle;
  }

  if (layerId === "shuiyuandiStation") {
    return createshuiyuandiStationStyle;
  }
  
  if (layerId === "qushuikou") {
    return createQushuikouStyle;
  }
  
  if (layerId === "wuranyuan") {
    return createWuranyuanStyle;
  }
  
  if (layerId === "ruhepaiwukou") {
    return createPaiwukouStyle;
  }
  
  if (layerId === "yujing") {
    return createYujingStyle;
  }

  // 默认点样式
  return function() {
    return new Style({
      image: new Circle({
        radius: 6,
        fill: new Fill({ color: "rgba(255, 0, 0, 0.6)" }),
        stroke: new Stroke({ color: "#fff", width: 2 }),
      }),
    });
  };
}

export default {
  createPointStyleFunction,
};